<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">

    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />




    <link rel="stylesheet" href="../content/css/font.css">
    <link rel="stylesheet" href="../content/css/xadmin.css">
    <link rel="stylesheet" href="../content/plugin/bootstrap/css/bootstrap.min.css">
    <link rel='stylesheet' href='../content/plugin/bootstrap/css/style.css' />

    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>

    <script type="text/javascript" src="../content/js/xadmin.js"></script>
    <script type="text/javascript" src="../content/js/cookie.js"></script>
    <script src="../content/lib/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../content/plugin/FileUpload/css/jquery.fileupload.css" />

    <link href="../content/plugin/jsTree/style.min.css" rel="stylesheet">
    <script src="../content/plugin/jsTree/jstree.min.js"></script>

    <link rel="stylesheet" href="../content/plugin/bootstrap/css/bootstrap-select.css">
    <script src="../content/plugin/bootstrap/js/bootstrap-select.js"></script>
    <style>
        .panel-primary {
            border-color: #009688 !important;
        }

        .panel-heading {
            background-color: #009688 !important;
            border-color: #009688 !important;
        }

        #myModal .modal-body .control-label {
            float: left;
            width: 20%;
            text-align: center;
        }
        #myModal  .row{
            width: 80%;
        }
    </style>

<body>
    <div class="app">
        <div class="x-nav">

            <span class="nav-header">
                <a href="">首页</a>>
                <a href="">进销存</a>>
                <a>
                    <cite>产品库</cite></a>
            </span>

        </div>
        <div class="x-body">


            <div class="row">
                <div class="row">

                    <div class="col-md-12">
                        <div style="    height: 30px;">
                            <div style="float: left">
                                物品编号：
                                <input type="text" v-model="search.code" placeholder="" autocomplete="off"
                                    style="height:30px;width: 100px;">
                                物品名称：
                                <input type="text" v-model="search.name" placeholder="" autocomplete="off"
                                    style="height:30px;width: 100px;">



                                <button class="layui-btn" v-on:click="getdata"><i
                                        class="layui-icon">&#xe615;</i></button>
                            </div>
                            <div style="float: right" v-cloak>
                                <span class="btn btn-success fileinput-button">
                                    <i class="glyphicon glyphicon-plus"></i>
                                    <span>导入数据</span>

                                    <input id="importperson" type="file" name="imgFile" multiple>

                                </span> &nbsp;&nbsp;

                                <button class="layui-btn"><a style="color:#ffffff" target="_blank"
                                        href="../content/model/productgood.xlsx">导入模板下载</a></button>


                                <button class="layui-btn" v-on:click="add"><i class="layui-icon"></i>添加</button>

                                <button class="layui-btn" v-if="quanxiancheck('product_del')"
                                    v-on:click="alldel">删除</button>


                            </div>
                        </div>

                        <table class="layui-table" style="margin-top:10px;">
                            <thead>
                                <tr>
                                    <th>
                                        <input type="checkbox" v-model="chooseall" @click="allcheck">
                                    </th>


                                    <th style="width: 120px;">商品条码</th>
                                    <th>中文品名</th>
                                    <th style="width: 200px;">日文品名</th>
                                    <th>英文名</th>
                                    <th>规格</th>

                                    <th>商品重量g</th>
                                    <th>采购价格</th>
                                    <th>销售价格</th>
                                    <th>生产国</th>
                                    <th>商品分类</th>
                                    <th>品牌名</th>
                                    <th>创建日期</th>
                                    <th>操作</th>

                                </tr>
                            </thead>
                            <tbody>
                                <tr v-for="uitem in arrayData" v-cloak>
                                    <td><input type="checkbox" :checked="idscheck(uitem)" @click="chooseid(uitem.id)">
                                    </td>


                                    <td>{{uitem.code}}</td>
                                    <td>{{uitem.name}}</td>
                                    <td>{{uitem.name_japan}}</td>
                                    <td>{{uitem.name_english}}</td>
                                    <td>{{uitem.format}}</td>
                                    <td>{{uitem.weight}}</td>
                                    <td>{{uitem.price}}</td>
                                    <td>{{uitem.xsprice}}</td>
                                    <td>{{uitem.manufactor}}</td>
                                    <td>{{uitem.type}}</td>
                                    <td>{{uitem.brand}}</td>
                                    <td>{{uitem.createtime}}</td>
                                    <td class="td-manage">
                                        <a title="编辑" v-on:click="vupdate(uitem)" href="javascript:;">
                                            <i class="layui-icon"></i>
                                        </a>
                                        <a title="删除" v-on:click="vdel(uitem)" href="javascript:;">
                                            <i class="layui-icon">&#xe640;</i>
                                        </a>

                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <div class="page">
                            <div>
                                <vue-nav :cur="search.page" :all="all" :allcount="allcount" :callback="callback">
                                </vue-nav>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>

        <div class="modal fade" id="addtypebox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
            aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content" id="myModal">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title" id="myModalLabel">添加信息</h4>
                    </div>
                    <div class="modal-body">

                        <form action="" v-on:submit.prevent="insert_type">
                            <fieldset>
                                <div class="control-group">
                                    <label for="input01" class="control-label">分类名称</label>
                                    <div class="controls">
                                        <input placeholder="" type="text" required class="form-control"
                                            v-model="addtypeobj.typename">
                                    </div>
                                </div>
                                <div class="control-group" style="overflow: visible;height: 33px;">
                                    <label for="input01" class="control-label">上级分类</label>
                                    <div class="controls">

                                        <input type="text" id="tree2" lay-filter="tree2" class="layui-input">

                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="input01" class="control-label">排序</label>
                                    <div class="controls">
                                        <input placeholder="" type="text" class="form-control" v-model="addtypeobj.seq">
                                    </div>
                                </div>

                            </fieldset>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="submit" class="btn btn-primary">确认</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!--添加-->
        <!-- 修改 -->
        <div class="modal fade" id="edittypebox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
            aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content" id="myModal">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title" id="myModalLabel">修改信息</h4>
                    </div>
                    <div class="modal-body">
                        <fieldset>
                            <div class="control-group">
                                <label for="input01" class="control-label">分类名称</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control"
                                        v-model="edittypeobj.typename">
                                </div>
                            </div>

                            <div class="control-group">
                                <label for="input01" class="control-label">排序</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="edittypeobj.seq">
                                </div>
                            </div>

                        </fieldset>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" v-on:click="update_type()">确认</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>




        <!-- 修改结束 -->
        <div class="modal fade" id="addbox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
            aria-hidden="true">
            <div class="modal-dialog" style="width:80%;">
                <div class="modal-content" id="myModal">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title" id="myModalLabel">添加信息</h4>
                    </div>
                    <div class="modal-body">
                        <form action="" v-on:submit.prevent="insert">
                            <fieldset>
                                <div class="row">
                                    <div class="control-group" style="overflow: visible;height: 33px;">
                                        <label for="input01" class="control-label">条码 <span style="color:red">※</span></label>
                                        <div class="controls">
                                            <input placeholder="" type="text" required class="form-control"
                                                v-model="addobj.code">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">中文品名 <span style="color:red">※</span></label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  required class="form-control"
                                                v-model="addobj.name">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">日文品名 <span style="color:red">※</span></label>
                                        <div class="controls">
                                            <input placeholder="" type="text" required class="form-control"
                                                v-model="addobj.name_japan">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">英文品名</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  class="form-control"
                                                v-model="addobj.name_english">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">规格 <span style="color:red">※</span></label>
                                        <div class="controls">
                                            <input placeholder="" type="text" required class="form-control"
                                                v-model="addobj.format">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">商品重量g <span style="color:red">※</span></label>
                                        <div class="controls">
                                            <input placeholder="" type="text" required  class="form-control"
                                                v-model="addobj.weight">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">采购价格</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  class="form-control"
                                                v-model="addobj.price">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">销售价格 <span style="color:red">※</span></label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  required class="form-control"
                                                v-model="addobj.xsprice">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">生产国</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  class="form-control"
                                                v-model="addobj.manufactor">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">商品分类</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  class="form-control"
                                                v-model="addobj.type">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">品牌名</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  class="form-control"
                                                v-model="addobj.brand">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">默认库存</label>
                                        <div class="controls">
                                            <input placeholder="" type="number"  class="form-control"
                                                v-model="addobj.kucun">
                                        </div>
                                    </div>
                                </div>




                            </fieldset>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="submit" class="btn btn-primary">确认</button>
                            </div>

                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!--添加结束-->
        <!--修改-->
        <div class="modal fade" id="editbox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
            aria-hidden="true">
            <div class="modal-dialog" style="width:80%;">
                <div class="modal-content" id="myModal">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title" id="myModalLabel">修改信息</h4>
                    </div>
                    <div class="modal-body">
                        <form action="" v-on:submit.prevent="update">
                            <fieldset>
                                <div class="row">
                                    <div class="control-group" style="overflow: visible;height: 33px;">
                                        <label for="input01" class="control-label">条码 ※</label>
                                        <div class="controls">
                                            <input placeholder="" type="text" required class="form-control"
                                                v-model="editobj.code">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">中文品名 ※</label>
                                        <div class="controls">
                                            <input placeholder="" type="text" required class="form-control"
                                                v-model="editobj.name">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">日文品名 ※</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  required class="form-control"
                                                v-model="editobj.name_japan">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">英文品名</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"   class="form-control"
                                                v-model="editobj.name_english">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">规格 ※</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  required class="form-control"
                                                v-model="editobj.format">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">商品重量g ※</label>
                                        <div class="controls">
                                            <input placeholder="" type="text" required class="form-control"
                                                v-model="editobj.weight">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">采购价格</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  class="form-control"
                                                v-model="editobj.price">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">销售价格 ※</label>
                                        <div class="controls">
                                            <input placeholder="" type="text" required class="form-control"
                                                v-model="editobj.xsprice">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">生产国</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  class="form-control"
                                                v-model="editobj.manufactor">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">商品分类</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  class="form-control"
                                                v-model="editobj.type">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-group">
                                        <label for="input01" class="control-label">品牌名</label>
                                        <div class="controls">
                                            <input placeholder="" type="text"  class="form-control"
                                                v-model="editobj.brand">
                                        </div>
                                    </div>
                                </div>
                               


                            </fieldset>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="submit" class="btn btn-primary">确认</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>


    </div>

</body>


<script src="../content/js/config.js"></script>
<link href="../content/plugin/sweetalert/sweetalert.css" rel="stylesheet">
<script src="../content/plugin/sweetalert/sweetalert.min.js"></script>
<script src="../content/plugin/bootstrap/js/bootstrap.min.js"></script>
<script src="../content/js/vue2.js"></script>
<script src="../content/js/vue-nav2.js"></script>
<script src="../content/plugin/FileUpload/js/vendor/jquery.ui.widget.js"></script>
<script src="../content/plugin/FileUpload/js/jquery.iframe-transport.js"></script>
<script src="../content/plugin/FileUpload/js/jquery.fileupload.js"></script>
<script src="../content/js/JsBarcode.all.js"></script>
<script src="../content/js/html2canvas.js"></script>
<script src="../content/js/jQuery.print.js"></script>
<script src="../content/js/jszip.min.js"></script>
<script src="../content/js/FileSaver.min.js"></script>




<script>
    Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };



    $(function () {

        $('#importperson').fileupload({
            autoUpload: true,//是否自动上传
            url: apiurl + "/upload/file",
            dataType: 'json',
            done: function (e, data) {

                console.log(data.result);
                if (data.result.code == 200) {

                    var filepath = data.result.file

                    layer.msg('导入中。。。', {
                        icon: 16
                        , shade: 0.01
                    });

                    $.post(apiurl + "/admin/jxc/productgood/import", { data: filepath }, function (data) {
                        if (data.status == 200) {
                            layer.closeAll('loading');
                            layer.msg(data.message);
                            vm.getdata();
                        }
                    })


                } else {
                    swal("上传出错了!", data.result.message, "error");

                }
            },
            progressall: function (e, data) {

            }
        }).prop('disabled', !$.support.fileInput)
            .parent().addClass($.support.fileInput ? undefined : 'disabled');



    });


    var vm = new Vue({
        el: ".app",
        data: {
            all: 0,
            arrayData: [],
            allcount: 0,
            menulist: [],
            cliniclist: [],
            statelist: [{ "id": 1, "name": "是" }, { "id": 0, "name": "否" }],
            addtypeobj: {
                pid: 0,
                path: 0
            },
            addobj: {

                wxprogram: 0,
                singleUrl: "",
                nokucun: 0,
                typeid: "",
                model: "",
                format: "",
                inprice: 0,
                outprice: 0,
                minnum: "",
                maxnum: "",
                desc: "",
                brand: "",
                manufacturer: "",
                istaobao: "0"

            },
            editobj: {},
            search: {
                typename: "",
                page: 1,
                rows: 10,
                wxprogram: '0',

                status: 1,
                type: localStorage.getItem("type")

            },
            supplierlist: [],
            manufacturerlist: [],
            buytypelist: [],
            brandlist: [],
            edittypeobj: {},
            ids: [],
            chooseall: false,
            filelist: [],
            filenamelist: []

        },
        components: {
            'vue-nav': Vnav
        },
        filters: {
            substr: function (value) {
                var length = 40;

                if (typeof (value) != "undefined" && value != null && value.length > length) {
                    value = value.substr(0, length) + "...";
                }
                return value;
            }
        },
        methods: {
            quanxiancheck: function (uitem) {
                //  console.log("quanxian", quanxian);
                //console.log(quanxian.indexOf(uitem));
                // if (quanxian.indexOf(uitem) != -1) {
                //     return true;
                // } else {
                //     return false;
                // }
                return true;

            },
            allcheck: function () {
                if (this.chooseall) {
                    for (var i = 0; i < this.arrayData.length; i++) {
                        this.ids.push(this.arrayData[i].id);
                    }
                } else {
                    this.ids = [];
                }
                console.log("ids", this.ids);
            },
            alldel: function () {
                var self = this;

                if (this.ids.length == 0) {


                    layer.msg("请选择");
                    return;
                }
                console.log("ids", this.ids);

                parent.layer.confirm('确定要删除吗?', {
                    btn: ['是', '否'] //按钮
                }, function () {
                    parent.layer.closeAll('dialog');
                    $.ajax({
                        url: apiurl + "/admin/jxc/productgood/del",
                        type: 'DELETE',
                        data: { "id": self.ids.join(",") },
                        success: function (result) {
                            if (result.status == 200) {
                                swal("系统提示", "已删除", "success");
                                self.getdata("");
                            } else {
                                swal("系统提示", "系统异常", "success");
                            }
                        }
                    });
                }, function () {

                });
            },
            qrexport: function () {
                var self = this;

                if (this.ids.length == 0) {


                    layer.msg("请选择");
                    return;
                }
                console.log("this.ids.length", this.ids.length);
                var list = this.arrayData;
                var arr = [];
                for (var i = 0; i < this.ids.length; i++) {
                    for (var j = 0; j < list.length; j++) {
                        if (this.ids[i] == list[j].id) {
                            arr.push(list[j]);
                            break;
                        }
                    }
                }
                console.log("arr", arr);


                this.filelist = [];
                this.download(arr, 0);
                console.log("filelength", this.filelist.length);


            },
            idscheck: function (uitem) {
                var list = this.ids;

                for (var i = 0; i < list.length; i++) {
                    if (list[i] == uitem.id) {
                        return true;
                    }
                }
                return false;
            },
            chooseid: function (id) {

                let idIndex = this.ids.indexOf(id)
                if (idIndex >= 0) {

                    this.ids.remove(id);

                } else {

                    this.ids.push(id);


                    //this.$forceUpdate();
                }
            },

            gettypelist: function () {


            },

            add: function () {

                this.gethancai("taobaoadd")


                $("#addbox").modal('show');
            },
            gethancai: function (id) {
                var self = this;

                $.post(apiurl + "/product/productgood/list", { "ishaocai": 1 }, function (data) {
                    $('#' + id).html("");
                    for (var i = 0; i < data.data.length; i++) {
                        var name = data.data[i].name;
                        $('#' + id).append("<option>" + name + "</option>")
                    }
                    $('#' + id).selectpicker('refresh');


                });
            },

            insert: function () {
                var self = this;



                $.post(apiurl + "/admin/jxc/productgood/add", this.addobj, function (data) {
                    if (data.status == 200) {
                        $("#addbox").modal('hide');

                        swal("success", "添加成功", "success");
                        self.getdata("");
                    } else {
                        swal("系统提示", data.message, "error");
                    }

                });
            },
            getdata: function (_keycontent) {  //查询数据

                var self = this;

                $.post(apiurl + "/admin/jxc/productgood/list", self.search, function (_result) {
                    console.log(_result);
                    self.arrayData = _result.data;
                    self.all = _result.allcount;
                    self.allcount = _result.count;
                });


            },
            callback: function (data) {
                var self = this;
                this.search.page = data;
                $.post(apiurl + "/admin/jxc/productgood/list", self.search, function (_result) {
                    self.arrayData = _result.data;
                    self.all = _result.allcount;
                    self.allcount = _result.count;
                });
            },
            vupdate: function (uitem) {

                setTimeout(() => {
                    this.editobj = uitem;
                    $('#taobaoedit').selectpicker('val', uitem.package.split(","));
                    loadedittype();

                }, 1000);

                $("#editbox").modal('show');

            },
            update: function () {
                var self = this;

                $.post(apiurl + "/admin/jxc/productgood/edit", this.editobj, function (data) {
                    if (data.status == 200) {
                        $("#editbox").modal('hide');
                        swal("success", "修改成功", "success");
                        self.getdata("");
                    } else {
                        swal("系统提示", data.message, "error");
                    }

                });

            },
            vdel: function (uitem) {
                var self = this;
                swal({
                    title: "确定要删除吗?",
                    text: "",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是",
                    cancelButtonText: '否',
                    closeOnConfirm: false
                }, function () {

                    $.ajax({
                        url: apiurl + "/admin/jxc/productgood/del",
                        type: 'DELETE',
                        data: { "ids": uitem.id },
                        success: function (result) {
                            if (result.status == 200) {
                                swal("系统提示", "已删除", "success");
                                self.getdata("");
                            } else {
                                swal("系统提示", "系统异常", "success");
                            }
                        }
                    });

                });
            },
            qrshow2: function (uitem) {
                var self = this;
                $("#qrbox").modal('show');
                var text = uitem.code;
                var canvas = document.getElementById("drawCanvas");
                canvas.width = 591; //☜
                canvas.height = 354;
                var ctx = canvas.getContext('2d');
                ctx.font = "26px '微软雅黑'";
                // 设置颜色

                // 设置水平对齐方式
                ctx.textAlign = "left";
                // 设置垂直对齐方式
                ctx.textBaseline = "middle";
                ctx.fillStyle = "#ffffff";
                ctx.fillRect(0, 0, canvas.width, canvas.height);
                ctx.fillStyle = "#000000";
                // var url = apiurl + "/mall/create_qrcode?text=" + text;
                //  $("#qrimg").attr("src", apiurl + "/mall/create_qrcode?text=" + text);

                //$("#qrimg").JsBarcode(text);

                JsBarcode("#qrimg", text, {
                    height: 140,
                    displayValue: false,

                });




                var image = document.getElementById("qrimg");
                image.onload = function () {
                    console.log("sss");
                    ctx.fillText("名称：" + uitem.name, 30, 30);
                    ctx.fillText("型号：" + uitem.model, 30, 60);
                    ctx.fillText("单位：" + uitem.unit, 30, 90);
                    ctx.drawImage(image, 0, 170, 591, 150);
                    ctx.fillText(text, 250, 330);

                };

            },
            qrshow: function (uitem) {
                var self = this;
                $("#qrbox").modal('show');
                var text = uitem.code;
                $("#qrimg").JsBarcode(text);


            },
            getgoodsbycode: function (code) {
                this.search.code = code;
                this.search.page = 1;
                this.getdata();
            },
            print: function () {
                var showConvas = document.getElementById("drawCanvas");
                $(convertCanvasToImage(showConvas)).print();
            }

        },
        created: function () {  //初始化事件里边去调用查询方法

            this.getdata("");
            // this.gettypelist();


        }
    });
    window.onload = function () {
        var code = "";
        var lastTime, nextTime;
        var lastCode, nextCode;

        document.onkeypress = function (e) {

            nextCode = e.which;
            nextTime = new Date().getTime();

            if (lastCode != null && lastTime != null && nextTime - lastTime <= 30) {
                code += String.fromCharCode(lastCode);
            } else if (lastCode != null && lastTime != null && nextTime - lastTime > 100) {
                code = "";
            }

            lastCode = nextCode;
            lastTime = nextTime;
        }

        this.onkeypress = function (e) {

            if (e.which == 13) {
                console.log("进来了", code);

                vm.getgoodsbycode(code);
                code = "";


            }
        }
    }
</script>